import request from '@/utils/request'
// import qs from 'qs'

export function getPhysicalApiArray (params) {
  var data = fromData(params)
  return request({
    url: 'physical/getPhysicalApiArray',
    method: 'post',
    data
  })
}

export function getPhysicalApiInfo (params) {
  var data = fromData(params)
  return request({
    url: 'physical/getPhysicalApiInfo',
    method: 'post',
    data
  })
}

export function addServerData (params) {
  var data = fromData(params)
  return request({
    url: 'physical/addServer',
    method: 'post',
    data
  })
}

export function editPhysicalApi (params) {
  var data = fromData(params)
  return request({
    url: 'physical/editPhysicalApi',
    method: 'post',
    timeout: 20 * 60 * 1000,
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}

// function fromData (params) {
//   var data = qs.stringify(params)
//   return data
// }
